package com.core.netty.http.work;

import io.netty.handler.codec.http.HttpHeaders;

import java.util.HashMap;
import java.util.Map;

public class HttpMyRequest implements MyRequest {
    private Map<String, Object> attr = new HashMap<>();
    private String host;
    private int port;
    private String url;
    private String method;
    private Map<String, String> pars = new HashMap<>();
    private HttpMySession session;

    private HttpHeaders headers;

    private Map<String, String> cookie = new HashMap<>();

    public void setCookie(String name, String value) {
        cookie.put(name, value);
    }

    public String getCookie(String name) {
        return cookie.get(name);
    }

    @Override
    public String getParameter(String name) {
        return this.pars.get(name) == null ? null : this.pars.get(name).toString();
    }

    public Map<String, String> getParameterMap() {
        return this.pars;
    }

    public void initPars(Map<String, String> cpar) {
        cpar.forEach((k, v) -> {
            pars.put(k, v);
        });
    }

    @Override
    public String getRemoteHost() {
        return this.host;
    }

    public void setRemoteHost(String host) {
        this.host = host;
    }

    @Override
    public Object getAttribute(String name) {
        return this.attr.get(name) == null ? null : this.attr.get(name).toString();
    }

    @Override
    public void setAttribute(String name, Object o) {
        this.attr.put(name, o);
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public HttpMySession getSession() {
        return session;
    }

    public void setSession(HttpMySession session) {
        this.session = session;
    }

    public HttpHeaders getHeaders() {
        return headers;
    }

    public void setHeaders(HttpHeaders headers) {
        this.headers = headers;
    }
}
